package com.xiaoxin.controller;

import com.xiaoxin.common.dto.ResponseBody;
import com.xiaoxin.common.entity.ShiroUser;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description:
 * @Author TongRui
 * @Date 2021/11/28
 * @Version V1.0
 **/
@Slf4j
@RestController
@RequestMapping("login")
public class LoginController {


    @GetMapping("admin")
    public ResponseBody adminLogin(String userName, String password){
        log.info("用户:{} 请求登录", userName);
        Subject subject = SecurityUtils.getSubject();
        subject.login(new UsernamePasswordToken(userName, password));
        ShiroUser shiroUser = (ShiroUser) subject.getPrincipal();
        log.info("登陆成功 shiroUser:{}", shiroUser);
        return ResponseBody.ok();
    }

}
